#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int a[200005],n,Max;
void dfs(int num,int lr,int lb,int sc){
    if(num==n+1){
        Max=max(Max,sc);
        return;
    }
    if(a[lr]!=a[num])dfs(num+1,num,lb,sc);
    else dfs(num+1,num,lb,sc+a[num]);
    if(a[lb]!=a[num])dfs(num+1,lr,num,sc);
    else dfs(num+1,lr,num,sc+a[num]);
    return;
}
void func1(){
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    Max=0;
    dfs(1,0,0,0);
    cout<<Max<<endl;
    return;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    a[0]=0;
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        func1();
    }
    return 0;
}
